﻿namespace TrainingData.Gpx
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml;
    using System.Xml.Serialization;
    using TrainingData.Common;
    using TrainingData.Common.Model;

    public class GpxReader : ISessionReader
    {
        private readonly string contents;

        public GpxReader(string contents)
        {
            this.contents = contents;
        }

        public Session GetSession()
        {
            var stream = new MemoryStream(UTF8Encoding.UTF8.GetBytes(this.contents));
            var gpx = (gpxType)new XmlSerializer(typeof(gpxType)).Deserialize(stream);

            return new Session(Microsoft.FSharp.Collections.ListModule.OfSeq(gpx.trk.Select(trk => new Activity("!!!1", trk.name, null))));
        }
    }
}
